#ifndef _SUDOKU_H_
#define _SUDOKU_H_

#include <stdio.h>
#include <string.h>

#define SUDOKU_WIDTH 9
#define SUDOKU_HEIGHT 9

struct sudoku
{
	char grid[SUDOKU_WIDTH][SUDOKU_HEIGHT];
};

/*! generate a random sudoku board
 * 	optionally allocate a new sudoku game if game==NULL
 */
struct sudoku* sudoku_generate(struct sudoku* game, int known_count);
/*! add a new known sudoku value to the grid
 */
int sudoku_add(struct sudoku* sudoku, int count);
void sudoku_reset(struct sudoku* sudoku);
/*! perform a quick solve algorithm.
 * 	Check for all spaces with only one possible value
 * 	Keep checking until non can be found. (this usually
 * 	solves the puzzle
 */
int sudoku_solve(struct sudoku* sudoku);

int sudoku_is_solved(struct sudoku* sudoku);

int sudoku_bad_square(struct sudoku* sudoku, int x, int y);

int sudoku_is_unique(struct sudoku* sudoku);
int _sudoku_is_unique(struct sudoku* sudoku);

/*! save the sudoku puzzle, and optionally the original puzzle (only the hints)
 * 	to a file. If original is null, the original grid is saved as zero's.
 */
int sudoku_save(struct sudoku* sudoku, struct sudoku* original, const char* file_name);
/*! load the sudoku puzzle, and optionally the original puzzle (only the hints)
 * 	from a file. If original is null, the original values are ignored.
 */
int sudoku_load(struct sudoku* sudoku, struct sudoku* original, const char* file_name);

#endif /*! _SUDOKU_H_ */
